package com.haiqi.modules.ship.service;

import com.github.pagehelper.PageInfo;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.dao.AisShipDynaMapper;
import com.haiqi.common.persistence.dao.ManningInfoMapper;
import com.haiqi.common.persistence.entity.ManningInfo;
import com.haiqi.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by hythzx on 2016/5/26.
 * 配员信息的service
 */
@Service
public class ShipManningService {
    
    @Autowired
    private ManningInfoMapper manningInfoMapper;

    @Autowired
    private AisShipDynaMapper aisShipDynaMapper;

    public PageInfo<ManningInfo> getDataList(ManningInfo manningInfo, PageBean page){
        PageUtils.generatePage(page);
        List<ManningInfo> dataList = manningInfoMapper.getDataList(manningInfo);
        PageInfo<ManningInfo> manningInfoList = new PageInfo<>(dataList);
        return manningInfoList;
    }

    public List<ManningInfo> getDataList(ManningInfo manningInfo){
        List<ManningInfo> dataList = manningInfoMapper.getDataList(manningInfo);
        return dataList;
    }

    public ManningInfo getManningInfo(int id){
        ManningInfo manningInfo = manningInfoMapper.selectByPrimaryKey(id);
        return manningInfo;
    }

    public boolean update(ManningInfo manningInfo){
        boolean success = false;
        int count = 0;
        if(manningInfo.getId() == null){
            count = manningInfoMapper.insert(manningInfo);
        }else{
            count = manningInfoMapper.updateByPrimaryKeySelective(manningInfo);
        }
        if(count > 0){
            success = true;
        }
        return success;
    }

    public boolean delete(int id){
        boolean success = false;
        int count = 0;
        count = manningInfoMapper.deleteByPrimaryKey(id);
        if(count > 0){
            success = true;
        }
        return success;
    }

   public ManningInfo selectByPrimaryKey(Integer id){
       return manningInfoMapper.selectByPrimaryKey(id);
   }


}
